<template>
  <div>
    <el-dialog
      title="新增合作商"
      width="80%"
      :visible.sync="visible"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="合作商名称" prop="name">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="联系人" prop="contact">
          <el-input v-model="form.contact" />
        </el-form-item>
        <el-form-item label="联系电话" prop="mobile">
          <el-input v-model="form.mobile" />
        </el-form-item>
        <el-form-item label="分成比例" prop="ratio">
          <el-input-number v-model="form.ratio" controls-position="right" :min="1" :max="50" @change="handleChange" />
        </el-form-item>
        <el-form-item label="账号" prop="account">
          <el-input v-model="form.account" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="form.password" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible=false">取 消</el-button>
        <el-button type="primary" @click="addsure">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { addParent } from '@/api/partener'
export default {
  name: 'DikedeAdd',

  data() {
    return {
      visible: false,
      password: '',
      mobile: '',
      account: '',
      ratio: 2,
      contact: '',
      name: '',
      form: {},
      rules: {
        name: [
          { required: true, message: '必填', trigger: 'blur' },
          { min: 1, max: 10, message: '必填', trigger: 'blur' }
        ],
        contact: [
          { required: true, message: '必填', trigger: 'blur' },
          { min: 1, max: 10, message: '必填', trigger: 'blur' }
        ],
        mobile: [
          { required: true, message: '必填', trigger: 'blur' },
          { min: 1, max: 11, message: '必填', trigger: 'blur' }
        ],
        ratio: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        account: [
          { required: true, message: '必填', trigger: 'blur' },
          { min: 1, max: 18, message: '必填', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '必填', trigger: 'blur' },
          { min: 1, max: 20, message: '必填', trigger: 'blur' }
        ]
      }
    }
  },

  watch: {
    visible(val) {
      if (!val) {
        this.$refs.form.resetFields()
      }
    }
  },

  mounted() {
  },

  methods: {
    handleChange() {
    },
    async addsure() {
      // console.log(res)
      try {
        await this.$refs.form.validate()
        await addParent(this.form)
        console.log(this.form)
        this.$message.success('新增成功')
        this.visible = false
        this.$parent.getParent()
      } catch (e) {
        console.log(e)
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
